window.tywx || (window.tywx = {}),
    tywx.ShareInterface = {
        OnShareAppMessageInfo: null,
        shareWithSharePoint: function (e, t, n, o) {
            if (!tywx.PropagateInterface._cachedShareConfig) return null;
            var i = tywx.PropagateInterface._shuffleByWeights();
            if (i && i[e]) {
                var a = i[e];
                tywx.ShareInterface.share(a.shareContent, a.sharePicUrl, a.sharePointId, a.shareSchemeId, t, n, o);
            }
        },
        setOnShareAppMessageInfoWithSharePoint: function (e) {
            if (tywx.PropagateInterface._cachedShareConfig) {
                var t = tywx.PropagateInterface._shuffleByWeights();
                if (t && t[e]) {
                    var n = t[e];
                    this.OnShareAppMessageInfo = {
                        title: n.shareContent,
                        imageUrl: n.sharePicUrl,
                        sharePointId: n.sharePointId,
                        shareSchemeId: n.shareSchemeId
                    };
                }
            }
        },
        setOnShareAppMessageInfo: function (e, t, n, o) {
            this.OnShareAppMessageInfo = {
                title: e,
                imageUrl: t,
                sharePointId: n,
                shareSchemeId: o
            };
        },
        getOnShareAppMessageInfo: function () {
            return this.OnShareAppMessageInfo;
        },
        getRandomOnShareAppMessageInfo: function () {
            var e = [];
            for (var t in tywx.PropagateInterface._cachedShareConfig) e.push(t);
            if (e && e.length > 0) {
                var n = Math.floor(1e4 * Math.random()) % e.length, o = e[n],
                    i = tywx.PropagateInterface._cachedShareConfig[o];
                if (i && i.length > 0) return {
                    title: i[n = Math.floor(1e4 * Math.random()) % i.length].shareContent,
                    imageUrl: i[n].sharePicUrl,
                    sharePointId: i[n].sharePointId,
                    shareSchemeId: i[n].shareSchemeId
                };
            }
            return null;
        },
        share: function (e, t, n, o, i, a, r) {
            try {
                tywx.IsWechatPlatform() && (tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [n, 1, o]),
                    wx.shareAppMessage({
                        title: e,
                        imageUrl: t,
                        query: "inviteCode=" + tywx.UserInfo.userId + "&sourceCode=" + n + "&inviteName=" + tywx.UserInfo.userName + "&imageType=" + o + "&extraInfo=" + (r || ""),
                        success: function (e) {
                            i && i(e), tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [n, 2, o]),
                            tywx.SystemInfo.openLocalRecord && tywx.TuyooSDK.freshLocalShareTimes();
                        },
                        fail: function (e) {
                            a && a(e);
                        },
                        complete: function () {
                        }
                    }));
            } catch (e) {
                tywx.LOGE("error:", "tywx.ShareInterface.share——" + JSON.stringify(e));
            }
        },
        shareWithCaptureInfo: function (e, t, n, o, i, a, r, s) {
            try {
                if (tywx.IsWechatPlatform()) if (tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [n, 1, o]),
                    s) {
                    var l = cc.director.getWinSize().width / tywx.SystemInfo.wxSystemInfo.screenWidth,
                        c = s.width, d = s.height;
                    canvas.toTempFilePath({
                        x: 0,
                        y: 0,
                        width: c / l * 2,
                        height: d / l * 2,
                        destWidth: 500 / l * 2,
                        destHeight: 400 / l * 2,
                        fileType: "jpg",
                        success: function (t) {
                            console.log("shareWithCaptureInfo share: toTempFilePath success");
                            var s = t.tempFilePath;
                            console.log("shareWithCaptureInfo share: toTempFilePath success imagUrl = ", s),
                                wx.shareAppMessage({
                                    title: e,
                                    imageUrl: s,
                                    query: "inviteCode=" + tywx.UserInfo.userId + "&sourceCode=" + n + "&inviteName=" + tywx.UserInfo.userName + "&imageType=" + o + "&extraInfo=" + (r || ""),
                                    success: function (e) {
                                        console.log("shareWithCaptureInfo share: tuyoo shareAppMessage success, params:" + JSON.stringify(e)),
                                        i && i(e);
                                        tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [n, 2, o, !0]);
                                    },
                                    fail: function (e) {
                                        console.log("shareWithCaptureInfo share: tuyoo shareAppMessage fail, params:" + JSON.stringify(e)),
                                        a && a(e);
                                    }
                                });
                        },
                        fail: function (e) {
                            console.log("dahu share: toTempFilePath fail, params:" + JSON.stringify(e)), a && a(e);
                        }
                    });
                } else wx.shareAppMessage({
                    title: e,
                    imageUrl: t,
                    query: "inviteCode=" + tywx.UserInfo.userId + "&sourceCode=" + n + "&inviteName=" + tywx.UserInfo.userName + "&imageType=" + o + "&extraInfo=" + (r || ""),
                    success: function (e) {
                        i && i(e), tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [n, 2, o]);
                    },
                    fail: function (e) {
                        a && a(e);
                    },
                    complete: function () {
                    }
                });
            } catch (e) {
                tywx.LOGE("error:", "tywx.ShareInterface.share——" + JSON.stringify(e));
            }
        }
    }, tywx.onShareAppMessageInit = function () {
    try {
        tywx.IsWechatPlatform() && wx.onShareAppMessage(function (e) {
            tywx.ShareInterface.setOnShareAppMessageInfoWithSharePoint("defaultSharePoint");
            var t = tywx.ShareInterface.getOnShareAppMessageInfo();
            return null == t && (t = tywx.ShareInterface.getRandomOnShareAppMessageInfo()),
                tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [t.sharePointId, 1, t.shareSchemeId]),
                {
                    title: t.title,
                    imageUrl: t.imageUrl,
                    query: "inviteCode=" + tywx.UserInfo.userId + "&sourceCode=" + t.sharePointId + "&inviteName=" + tywx.UserInfo.userName + "&imageType=" + t.shareSchemeId,
                    success: function (e, n) {
                        tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [t.sharePointId, 2, t.shareSchemeId]),
                        tywx.SystemInfo.openLocalRecord && tywx.TuyooSDK.freshLocalShareTimes();
                    },
                    fail: function () {
                    },
                    complete: function () {
                    }
                };
        });
    } catch (e) {
        tywx.LOGE("error:", "tywx.ShareInterface.share——" + JSON.stringify(e));
    }
}, tywx.onShareAppMessageInit()
